import re
import jieba
import jieba.posseg as pseg

INTENT_DICT = {
    "gen_resume": {"生成简历","写简历","做简历","简历生成","导出简历","word简历","简历word"},
    "download": {"下载","导出","保存"},
    "query_delivery": {"投递记录","投递进度","我的投递","查看投递"}
}
NEGATIVE = {"不要","取消","算了","不需要"}

def score_intents(question: str) -> list:
    if not question:
        return []
    jieba.load_userdict("boss_zhipin_dict.txt")
    tokens = list(jieba.cut(question))
    words_pos = list(pseg.cut(question))
    token_set = set(tokens)

    results = []
    for intent, triggers in INTENT_DICT.items():
        score = 0
        # 触发词/同义词命中
        for t in triggers:
            if t in question or t in token_set:
                score += 2

        # 动词+名词模式（简单示例）
        has_v = any(flag.startswith("v") for _, flag in words_pos)
        has_n = any(flag.startswith("n") for _, flag in words_pos)
        if has_v and has_n:
            score += 2

        # 负向词惩罚
        if any(neg in question for neg in NEGATIVE):
            score -= 3

        # 阈值判断
        if score >= 3:
            results.append((intent, score))

    # 分数排序，返回多意图（如需只要一个，取 results[0]）
    results.sort(key=lambda x: x[1], reverse=True)
    return results

# 用法：
intents = score_intents("帮我生成简历并下载成word")
print(intents)
# 可能返回：[("gen_resume", 5), ("download", 3)]
